function displays(amin, amax, dat, nx1, nx2, LEGEND, NLINES, npart,...
  iup, shrink, ialign, iresid)
% this subfunction plots a curve
% most of the simulation programs call eprplt, which then calls this
% function. However, upenf calls it directly so if the parameters in
% the call function are modified, need to modify upenf

global resid ssq
global maxx maxy
global lob1e lobfe lob1c lobfc

scrsz = get(0, 'ScreenSize');
maxx = scrsz(3);
maxy = scrsz(4);

% npart = 0, only one curve to plot
%         1, plotting first curve of 2
%         2, plotting second curve of 2

% leave space for labeling of plot
ileft = 0.28*maxx + 5;
npoint = nx2 - nx1 + 1;

amid = 0.5*(amax+amin);
% allow 70% of y axis for data, rest for boundaries and residuals
scaley = (0.70*single(maxy))/abs(amax-amin);
% right hand boundary covers 3% of horizontal window
scalex = (0.97*single(maxx) - single(ileft))/npoint;
% scalex = (0.97*single(maxx))/npoint;
for i = nx1:nx2
  locx = scalex*(i-nx1); % + ileft;
  % allow 20% at bottom for border + residuals so center plot at
  % 0.36*maxy, remember that 0 for maxy is at top
  if npart == 1
    locy = round(0.36*single(maxy) - (dat(i)-amid)*scaley*shrink...
      + real(iup+ialign));
  else
    locy = round(0.36*single(maxy) - (dat(i)-amid)*scaley*shrink...
      + real(iup));
  end
  if locy < 0
    locy = 0;
  end
  if locy > maxy
    locy = maxy;
  end
  if i == nx1
    % for first point, store locations of baseline
    if npart == 1
      lob1c = locy;
    else
      lob1e = locy;
    end
    XY = [locx locy];
  else
%     locx = [locx locx];
%     locy = [locy locy];
    hold on;
plot(locx, locy, 'r');
  end
end
locx = locx';
locy = locy';
% hold on;
% plot(locx, locy, 'r');
% disp(['locx: ' num2str(locx)]);
% disp(['locy: ' num2str(locy)]);

% values of loc at end of loop are for last point
if npart == 1
  lobfc = locy;
else
  lobfe = locy;
end
if npart ~= 2
  return;
end
% after plotting second curve, plot residuals, if requested
if iresid == 0
  return;
end
% calculate and output the sum of the squares of the residuals
rmax = resid(nx1);
rmin = resid(nx1);
ssq = resid(nx1)^2;
for ij = (nx1+1):nx2
  ssq = ssq + resid(ij)^2;
  if resid(ij) > rmax
    rmax = resid(ij);
  end
  if resid(ij)< rmin
    rmin = resid(ij);
  end
end
rmid = 0.5*(rmax+rmin);
rscaley = 0.12*single(maxy)/(rmax-rmin);
% nlinet = NLINES + 1;
for ij = nx1:nx2
  locx2 = scalex*(ij-nx1)+ileft;
  locy2 = 0.82*single(maxy)-(resid(ij)-rmid)*rscaley;
  if ij == nx1
    XY = [locx2(ij) locy2(ij)];
  else
    locx2 = [locx2 locx2];
    locy2 = [locy2 locy2];
  end
end
locx2 = locx2';
locy2 = locy2';
% plot(locx2, locy2, 'g');
% disp(['locx2: ' num2str(locx2)]);
% disp(['locy2: ' num2str(locy2)]);
return;
end